package com.skiving.cloud.auth.logutils;

import org.noear.solon.core.handle.Context;

public class IpUtils {
    public static String getIpAddress(Context ctx) {
        String ip = ctx.header("X-Forwarded-For");
        if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
            ip = ctx.header("Proxy-Client-IP");
        }
        if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
            ip = ctx.header("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
            ip = ctx.realIp();
        }
        return ip;
    }
}
